<script>
	Namespace.register("EBCMS.[namespace]");
	$(function(){
		EBCMS.[namespace].refresh = function refresh(dir){
			if (dir) {
				EBCMS.[namespace].dir = dir;
			};
			EBCMS.CORE.load({
				url:'{:U('Template/index')}',
				queryParams:{
					dir:EBCMS.[namespace].dir,
				},
				tpl:'[namespace]-table',
				target:'#[namespace]_main',
			});
		};
		// 获取添加表单
		EBCMS.[namespace].add = function add(path){
			EBCMS.CORE.get({
				url:'{:U('Template/add')}',
				queryParams:{
					path:path,
				},
				target:'#lgModal .modal-content',
				loadAfter:function(data,p){
					$('#lgModal').modal('toggle');
				},
			});
		};
		// 获取修改表单
		EBCMS.[namespace].save = function save(filename){
			EBCMS.CORE.get({
				url:'{:U('Template/save')}',
				queryParams:{
					filename:filename,
				},
				target:'#lgModal .modal-content',
				loadAfter:function(data,p){
					$('#lgModal').modal('toggle');
				},
			});
		};
		EBCMS.[namespace].del = function del(filename){
			EBCMS.MSG.confirm('确定删除该条内容吗？<br/>删除后不可恢复！',function(){
				EBCMS.CORE.submit({
					url:'{:U('Template/delete')}',
					queryParams:{
						filename:filename,
					},
					success:function(data){
						EBCMS.MSG.tips('删除成功！');
						EBCMS.[namespace].refresh();
					}
				});
			});
		};
	});
</script>
<div class="header">
	<div class="header-title" onclick="EBCMS.[namespace].refresh();">模板管理</div>
</div>
<div class="body" style="bottom:0px;" id="[namespace]_main">
</div>
<script id="[namespace]-table" type="text/html">
	<ul class="list-group tree tree_first" style="border-top: 1px solid #ddd;border-right: 1px solid #ddd;border-bottom: 1px solid #ddd;">
		{{include '[namespace]-table-item'}}
	</ul>
</script>
<script id="[namespace]-table-item" type="text/html">
	{{each rows as v n}}
		{{if v.rows}}
		<li class="list-group-item">
			<div class="btn-group btn-group-xs pull-right" role="group" aria-label="...">
				{{if access(0,'[namespace]','add')}}
				<a class="btn btn-default btn-xs" href="javascript:EBCMS.[namespace].add('{{v.path}}');" role="button">添加</a>
				{{/if}}
			</div>
			<span class="glyphicon glyphicon-folder-open"></span>&nbsp;&nbsp;{{v.text}}
		</li>
		<li class="list-group-item nopadding">
			<ul class="list-group tree">
				{{include '[namespace]-table-item' v}}
			</ul>
		</li>
		{{else}}
		<li class="list-group-item">
			<div class="btn-group btn-group-xs pull-right" role="group" aria-label="...">
				{{if access(0,'[namespace]','delete')}}
				<a class="btn btn-default btn-xs" href="javascript:EBCMS.[namespace].del('{{v.filename}}');" role="button">删除</a>
				{{/if}}
				{{if access(0,'[namespace]','save')}}
				<a class="btn btn-default btn-xs" href="javascript:EBCMS.[namespace].save('{{v.filename}}');" role="button">修改</a>
				{{/if}}
			</div>
			<span class="glyphicon glyphicon-file"></span>&nbsp;{{v.text}}
		</li>
		{{/if}}
	{{/each}}
</script>